chs = int(input(">"))

maxi = []

if len(str(chs)) != 4:
    print("0")

else:  

    def IsN1111(chs):
        
        if chs <= 1:
            return False
        
        for i in range(2, int(chs**0.5) + 1):
            if chs % i == 0:
                return False
            
        return True    
    def IsN1110(chs):
        global chs1110
        chs1110 = int(str(chs)[:-1])
        
        if chs1110 <= 1:
            return False
        for i in range(2, int(chs1110**0.5) + 1):
            if chs1110 % i == 0:
                return False
        return True  
    def IsN0111(chs):
        global chs0111
        chs0111 = int(str(chs)[1:])

        if chs0111 <= 1:
            return False
        for i in range(2, int(chs0111**0.5) + 1):
            if chs0111 % i == 0:
                return False
        return True 
    def IsN1100(chs):
        global chs1100
        chs1100 = int(str(chs)[:-2])

        if chs1100 <= 1:
            return False
        for i in range(2, int(chs1100**0.5) + 1):
            if chs1100 % i == 0:
                return False
        return True  
    def IsN0110(chs):
        global chs0110
        chs0110 = int(str(chs)[1:][:-1])

        if chs0110 <= 1:
            return False
        for i in range(2, int(chs0110**0.5) + 1):
            if chs0110 % i == 0:
                return False
        return True 
    def IsN0011(chs):
        global chs0011
        chs0011 = int(str(chs)[2:])

        if chs0011 <= 1:
            return False
        for i in range(2, int(chs0011**0.5) + 1):
            if chs0011 % i == 0:
                return False
        return True 
    def IsN1000(chs):
        global chs1000
        chs1000 = int(str(chs)[:-3])

        if chs1000 <= 1:
            return False
        for i in range(2, int(chs1000**0.5) + 1):
            if chs1000 % i == 0:
                return False
        return True 
    def IsN0100(chs):
        global chs0100
        chs0100 = int(str(chs)[1:][:-2])

        if chs0100 <= 1:
            return False
        for i in range(2, int(chs0100**0.5) + 1):
            if chs0100 % i == 0:
                return False
        return True
    def IsN0010(chs):
        global chs0010
        chs0010 = int(str(chs)[2:][:-1])

        if chs0010 <= 1:
            return False
        for i in range(2, int(chs0010**0.5) + 1):
            if chs0010 % i == 0:
                return False
        return True
    def IsN0001(chs):
        global chs0001
        chs0001 = int(str(chs)[3:])

        if chs0001 <= 1:
            return False
        for i in range(2, int(chs0001**0.5) + 1):
            if chs0001 % i == 0:
                return False
        return True

    if IsN1111(chs) == True:
        print(chs)
    elif IsN1111(chs) == False:
        if IsN1110(chs) == True:
            maxi.append(chs1110)
        if IsN0111(chs) == True:
            maxi.append(chs0111)
        if IsN1100(chs) == True:
            maxi.append(chs1100)
        if IsN0110(chs) == True:
            maxi.append(chs0110)
        if IsN0011(chs) == True:
            maxi.append(chs0011)
        if IsN1000(chs) == True:
            maxi.append(chs1000)
        if IsN0100(chs) == True:
            maxi.append(chs0100)
        if IsN0010(chs) == True:
            maxi.append(chs0010)
        if IsN0001(chs) == True:
            maxi.append(chs0001)
        
        if len(maxi) == 0:
            print("0")
        else:
            ans = max(maxi)
            print(ans)